package com.xuzimian.globaldemo.spring.springsecurity.config;

import com.xuzimian.globaldemo.spring.springsecurity.service.SecuredSpittleService;
import com.xuzimian.globaldemo.spring.springsecurity.service.SpittleService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;

@Configuration
@EnableGlobalMethodSecurity(securedEnabled=true)
public class SecuredConfig extends GlobalMethodSecurityConfiguration {

  @Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
    auth.inMemoryAuthentication().withUser("user1").password("password1").roles("USER");
  }
  
  @Bean
  public SpittleService spitterService() {
    return new SecuredSpittleService();
  }

}
